package com.wlt.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wlt.mapper.ItemsMapper;
import com.wlt.mapper.ItemsMapperCustom;
import com.wlt.domain.Items;
import com.wlt.domain.ItemsCustom;
import com.wlt.domain.ItemsQueryVo;
import com.wlt.exception.CustomException;
import com.wlt.service.ItemsService;

@Service("itemsService")
public class ItemsServiceImpl implements ItemsService {
	@Autowired
	private ItemsMapperCustom itemsMapperCustom;
	@Autowired
	private ItemsMapper itemsMapper;
	@Override
	public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo) throws Exception {
		return itemsMapperCustom.findItemsList(itemsQueryVo);
	}
	@Override
	public ItemsCustom finItemsById(Integer id) throws Exception {
		Items items=itemsMapper.selectByPrimaryKey(id);
		//中间对商品信息进行业务处理
		if(items == null) {
			throw new CustomException("修改的商品信息不存在!");
		}
		//......
		//返回ItemsCustom
		ItemsCustom itemsCustom=null;
		//将items的属性值拷贝到itemsCustom
		if(items != null) {
			itemsCustom=new ItemsCustom();
			BeanUtils.copyProperties(items, itemsCustom);
		}
		return itemsCustom;
	}
	@Override
	public void updateItems(Integer id, ItemsCustom itemsCustom) throws Exception {
		//业务校验  通常在service接口对关键参数进行校验
		//校验id是否为空,如果为空抛出异常
		
		
		//更新商品信息 使用updateByPrimaryKeyWithBLOBs根据id更新items表中的所有字段包括大文本类型的字段
		//updateByPrimaryKeyWithBLOBs必须传入id
		itemsCustom.setId(id);
		itemsMapper.updateByPrimaryKeyWithBLOBs(itemsCustom);
	}

}
